<?php
/**
 * 路由
 */
namespace App\Models\MainDB\Access;

use Illuminate\Database\Eloquent\Model;

class Route extends Model
{
    protected $table = 'ln_route';

    protected $primaryKey = 'id';

    protected $fillable = [
        'id', //主键
        'ctr_dir', //控制器所在目录
        'ctr', //控制器
        'action', //方法
        'uri', //路由地址
        'method', //请求方式
    ];

    public $timestamps = false;

    //获取路由，根据权限id做映射
    public function getRoutesWithAccessIdMap($accessIds)
    {
        $data = $this->from('ln_route as r')
            ->leftJoin('ln_access_route_join as arj', 'r.id', '=', 'arj.route_id')
            ->select('arj.access_id', 'arj.route_id', 'r.uri', 'r.method')
            ->whereIn('arj.access_id', $accessIds)
            ->get()->toArray();
        $routes = [];
        foreach ($data as $v) {
            $routes[$v['access_id']][] = $v;
        }
        return $routes;
    }
}